﻿@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits ValidateBase<TValue>

@if (IsShowLabel)
{
    <label class="form-label" required="@Required" for="@Id">@DisplayText</label>
}
<BootstrapInputGroup class="@ClassName">
    <input type="hidden" @attributes="AdditionalAttributes" id="@Id" disabled="@Disabled" @bind-value="@CurrentValueAsString"></input>
    <div class="input-locker-loading">
        @if(IsShowPrompt) 
        {
            <span>@Prompt</span>
        }
        <Spinner Color="Color.Primary" Size="Size" class="@SpinnerClassName"/>
    </div>
</BootstrapInputGroup>

@code{
    /// <summary>
    /// 获得 class 样式集合
    /// </summary>
    private string? ClassName => CssBuilder.Default("form-control input-locker")
        .AddClass(CssClass).AddClass(ValidCss)
        .Build();

    /// <summary>
    /// 获得 class 样式集合
    /// </summary>
    private string? SpinnerClassName => CssBuilder.Default()
        .AddClass("input-locker-spinner", IsShowPrompt)
        .Build();

    private new bool IsDisabled { get; set; } = true;
    private bool IsShowPrompt => !string.IsNullOrWhiteSpace(Prompt);

    /// <summary>
    /// 获得/设置 数据加载时提示文本内容
    /// </summary>
    [Parameter]
    public string? Prompt { get; set; }

    /// <summary>
    /// 获得 / 设置 Spinner 大小 默认 None 无设置
    /// </summary>
    [Parameter]
    public Size Size { get; set; }
}
